$(function(){
	
	var options = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
 
        dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type) 
        clearForm: true        // clear all form fields after successful submit 

    }; 
 

    $('#form').submit(function() { 

        $(this).ajaxSubmit(options); 

        return false; 
    });

    var $div_search_result    = $('#div_search_result');
    var $item_id    = $('#item_id');
    var $url        = $('#url');
    var $keywords        = $('#keywords');

    //查询排名
    var $btnSearch = $('#btnSearch');
    $btnSearch.click(function(){
        var item_id     = $item_id.val();
        var url         = $url.val();
        var keywords    = $keywords.val();

        var params = {
            'item_id':item_id,
                'url':url,
            'keywords':keywords
        };

        $btnSearch.attr('disabled',true).val('查询中，请耐心等待...');

        $div_search_result.load('/index.php/Admin/JdRank/search_result?' + $.param(params),function(){
            $btnSearch.attr('disabled',false).val('查询');
        });

    });

});


function showRequest(formData, jqForm, options) { 
    //var queryString = $.param(formData); 
    return true; 
} 

function showResponse(data, statusText, xhr, $form)  { 
	if(data.success){
		alert(data.message);
		location.href= '/index.php/Admin/JdRank/';
	}else{
		alert(data.message);
	}
}